<template>
  <template v-for="(item, index) in options" :key="index">
    <el-sub-menu v-if="item.type === MENUTYPE.目录" :index="item.id + ''">
      <template #title>
        <el-icon v-if="iconsnames.includes(item.icon)">
          <component :is="(ElementPlusIconsVue as any)[item.icon]" />
        </el-icon>
        <span>{{ item.name }}</span>
      </template>
      <menu_item v-if="item.childMenus" :options="item.childMenus">
      </menu_item>
    </el-sub-menu>
    <el-menu-item @click="onClick(item)" v-else-if="item.type === MENUTYPE.菜单" :index="item.id + ''">
      <el-icon v-if="iconsnames.includes(item.icon)">
        <component :is="(ElementPlusIconsVue as any)[item.icon]" />
      </el-icon>
      <span>{{ item.name }}</span>
    </el-menu-item>
  </template>
</template>
<script setup lang="ts">
import { useRouter } from "vue-router";
import { ElSubMenu, ElMenuItem, ElIcon } from "element-plus";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import { MENUTYPE } from "@b/model/enum";

interface prop {
  options: interfaceMenu[]
}
const router = useRouter();
const iconsnames = Object.keys(ElementPlusIconsVue);
defineProps<prop>();
const onClick = (item: interfaceMenu) => {
  router.push(item.router);
};
</script>

<style scoped>
.menuitem {
  width: 100%;
}
</style>
